﻿using Bussiness.HomeLoanTrust;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using Bussiness.HomeLoanMortgage;
using FOModels.HomeLoanTrust;
using FOModels.HomeLoanMortgage;
using Bussiness.Company;
using FOModels.Company;
using System.Net;
using Bussiness.Product;
using FOModels.Product;
using Bussiness.ProductFAQ;
using FOModels.ProductFAQ;
using FOSystem.CultureHelper;
using Bussiness.Language;
using FOModels.Language;
using Bussiness.Status;
using FOModels.Status;
using System.Configuration;
using System.Net.Mail;
namespace FO.Controllers
{
    public class HomeLoanMortgageController : CultureController
    {
        //
        // GET: /HomeLoanMortgage/

        public ActionResult Index()
        {
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            ProductBLL probll = new ProductBLL();
            int HomeLoanMortgageID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["HomeLoanMortgageID"].ToString());
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ViewBag.ProDes = probll.getProductByID(HomeLoanMortgageID, lang.LangID);
            ViewBag.HomeLoanPlan = bll.getHomeLoanPlan(lang.LangID);
            ViewBag.HomeLoanMortgage = bll.getHomeLoanMortgageDefault(2, lang.LangID);

            return View();
        }

        public ActionResult TermSavingByProvider(int CompanyID)
        {
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductBLL probll = new ProductBLL();
            ViewBag.HomeLoanPlan = bll.getHomeLoanPlan(lang.LangID);
            ViewBag.HomeLoan = bll.getHomeLoanMortgageDefaultByProvider(1, CompanyID, lang.LangID);
            return View();

        }
        public ActionResult Detail(int HomeLoanMortgageID)
        {
            int HomeLoanMortgageIDs = int.Parse(System.Configuration.ConfigurationManager.AppSettings["HomeLoanMortgageID"].ToString());
            HomeLoanTrustBLL termbll = new HomeLoanTrustBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductFAQBLL faqbll = new ProductFAQBLL();
            HomeLoanTrustModels term = new HomeLoanTrustModels();
            CompanyBLL combll = new CompanyBLL();
            term = termbll.getHomeLoanByID(HomeLoanMortgageID, lang.LangID);
          //  ViewBag.TermRelati = termbll.gethomeloamtrustrelati(2, term.CompanyID, term.HomeLoanID, lang.LangID);
            ViewBag.FAQ = faqbll.getfaqbyproid(HomeLoanMortgageIDs, lang.LangID);
            ViewBag.TermInterest = combll.getTableHomeLoanMortgageInterestbyComID(term.CompanyID);
            return View(term);
        }

        [Authorize(Roles = "8,9")]
        public ActionResult ShowCase()
        {
            return View();
        }
        public ActionResult HomeLoanMortgageInfo(int HomeLoanMortgageID)
        {
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            HomeLoanTrustModels list = new HomeLoanTrustModels();
            LanguageBLL langbll = new LanguageBLL();
            int HomeLoanMortgageIDs = int.Parse(System.Configuration.ConfigurationManager.AppSettings["HomeLoanMortgageID"].ToString());
            ProductFAQBLL faqbll = new ProductFAQBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            list = bll.getHomeLoanByID(HomeLoanMortgageID, lang.LangID);
            ViewBag.FAQ = faqbll.getfaqbyproid(HomeLoanMortgageIDs, lang.LangID);
            Fcom.IDLib.SaveMoneyID.AccountsynClient client = new Fcom.IDLib.SaveMoneyID.AccountsynClient();
            FOModels.User.User us = null;
            if (User.Identity.Name != "")
            {
                Fcom.IDLib.SaveMoneyID.FullUserInfo fullinfo = client.getUserInfo(User.Identity.Name);
                us = new FOModels.User.User();
                us.DisplayName = fullinfo.Fullname;
                us.Email = fullinfo.Email;
                us.GroupID = fullinfo.GroupID;
                us.Status = fullinfo.Status;
                us.Username = fullinfo.Username;
                us.Phone = fullinfo.Phone;
                us.DOB = fullinfo.DateOfBirth;

            }
            ViewBag.UserInfo = us;

            return View(list);
        }

        [Authorize(Roles = "8,9")]
        public ActionResult ManagerHomeLoanMortgage()
        {
            return View();
        }
        public JsonResult getHomeLoanTrustJson()
        {
            HomeLoanTrustBLL cardbll = new HomeLoanTrustBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            List<HomeLoanTrustModels> list = new List<HomeLoanTrustModels>();
            list = cardbll.getall(2, lang.LangID);
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateHomeLoan(int HomeLoanID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            List<HomeLoanCategoryModels> cate = new List<HomeLoanCategoryModels>();
            List<HomeLoanPlanModels> plan = new List<HomeLoanPlanModels>();
            CompanyBLL company = new CompanyBLL();
            List<CompanyModels> com = new List<CompanyModels>();
            HomeLoanTrustModels saving = new HomeLoanTrustModels();
            com = company.getCompany(lang.LangID);
            plan = bll.getHomeLoanPlan(lang.LangID);
            cate = bll.getallcarloancate(lang.LangID);
            saving = bll.getHomeLoanByIDManager(HomeLoanID, lang.LangID);
            ViewBag.HomeLoanPlanListID = new SelectList(plan, "HomeLoanPlanID", "HomeLoanPlanName", saving.HomeLoanPlanID);
            ViewBag.CompanyListID = new SelectList(com, "CompanyID", "Name", saving.CompanyID);
            Models.HomeLoan sa = new Models.HomeLoan();
            sa.HomeLoanName = saving.HomeLoanName;
            sa.CompanyID = saving.CompanyID;
            sa.MinimumBalance = saving.MinimumBalance;
            sa.MaximumBalance = saving.MaximumBalance;
            sa.Description = WebUtility.HtmlDecode(saving.Description);
            sa.Benefit = WebUtility.HtmlDecode(saving.Benefit);
            sa.FeeContent = WebUtility.HtmlDecode(saving.FeeContent);
            sa.MoreInfo = WebUtility.HtmlDecode(saving.MoreInfo);
            sa.HomeLoanPlanID = saving.HomeLoanPlanID;
            sa.Display = saving.Display;
            sa.HomeLoanID = saving.HomeLoanID;
            return View(sa);
        }

        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateHomeLoan(Models.HomeLoan de)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            List<HomeLoanCategoryModels> cate = new List<HomeLoanCategoryModels>();
            List<HomeLoanPlanModels> plan = new List<HomeLoanPlanModels>();
            CompanyBLL company = new CompanyBLL();
            List<CompanyModels> com = new List<CompanyModels>();
            HomeLoanTrustModels saving = new HomeLoanTrustModels();
            plan = bll.getHomeLoanPlan(lang.LangID);
            cate = bll.getallcarloancate(lang.LangID);
            com = company.getCompany(lang.LangID);
            saving = bll.getHomeLoanByIDManager(de.HomeLoanID, lang.LangID);
            ViewBag.HomeLoanPlanListID = new SelectList(plan, "HomeLoanPlanID", "HomeLoanPlanName", saving.HomeLoanPlanID);
            ViewBag.CompanyListID = new SelectList(com, "CompanyID", "Name", saving.CompanyID);
            if (saving != null)
            {
                saving.HomeLoanName = de.HomeLoanName;
                saving.CompanyID = de.CompanyID;
                saving.MinimumBalance = de.MinimumBalance.Replace(".", "").Replace(".", "").Replace(".", "");
                saving.MaximumBalance = de.MaximumBalance.Replace(".", "").Replace(".", "").Replace(".", "");
                saving.Description = WebUtility.HtmlEncode(de.Description);
                saving.Benefit = WebUtility.HtmlEncode(de.Benefit);
                saving.FeeContent = WebUtility.HtmlEncode(de.FeeContent);
                saving.MoreInfo = WebUtility.HtmlEncode(de.MoreInfo);
                saving.HomeLoanPlanID = de.HomeLoanPlanID;
                saving.Display = de.Display;
                bll.UpdateHomeLoan(saving, lang.LangID);

                return RedirectToAction("ManagerHomeLoanMortgage");
            }
            return View();
        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertHomeLoan()
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            List<HomeLoanCategoryModels> cate = new List<HomeLoanCategoryModels>();
            List<HomeLoanPlanModels> plan = new List<HomeLoanPlanModels>();
            CompanyBLL company = new CompanyBLL();
            List<CompanyModels> com = new List<CompanyModels>();
            plan = bll.getHomeLoanPlan(lang.LangID);
            cate = bll.getallcarloancate(lang.LangID);
            com = company.getCompany(lang.LangID);
            ViewBag.HomeLoanPlanListID = new SelectList(plan, "HomeLoanPlanID", "HomeLoanPlanName");
            ViewBag.CompanyListID = new SelectList(com, "CompanyID", "Name");
            return View();

        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertHomeLoan(FO.Models.HomeLoanInsert de)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            List<HomeLoanCategoryModels> cate = new List<HomeLoanCategoryModels>();
            CompanyBLL company = new CompanyBLL();
            List<CompanyModels> com = new List<CompanyModels>();
            List<HomeLoanPlanModels> plan = new List<HomeLoanPlanModels>();

            cate = bll.getallcarloancate(lang.LangID);
            plan = bll.getHomeLoanPlan(lang.LangID);
            com = company.getCompany(lang.LangID);

            ViewBag.HomeLoanPlanListID = new SelectList(plan, "HomeLoanPlanID", "HomeLoanPlanName");
            ViewBag.CompanyListID = new SelectList(com, "CompanyID", "Name");

            if (ModelState.IsValid)
            {
                HomeLoanTrustModels saving = new HomeLoanTrustModels();
                HomeLoanTrustModels savingLang = new HomeLoanTrustModels();
                saving.HomeLoanName = de.HomeLoanName;
                saving.CompanyID = de.CompanyID;
                saving.MinimumBalance = de.MinimumBalance.Replace(".", "").Replace(".", "").Replace(".", "");
                saving.MaximumBalance = de.MaximumBalance.Replace(".", "").Replace(".", "").Replace(".", "");
                saving.Description = WebUtility.HtmlEncode(de.Description);
                saving.Benefit = WebUtility.HtmlEncode(de.Benefit);
                saving.FeeContent = WebUtility.HtmlEncode(de.FeeContent);
                saving.MoreInfo = WebUtility.HtmlEncode(de.MoreInfo);
                saving.HomeLoanPlanID = de.HomeLoanPlanID;
                saving.Display = false;
                bll.InsertHomeLoanMortgage(saving);
                HomeLoanTrustModels savingItem = bll.getTOP1();
                saving.HomeLoanID = savingItem.HomeLoanID;


                savingLang.HomeLoanID = savingItem.HomeLoanID;
                savingLang.HomeLoanName = de.HomeLoanNameLang;
                savingLang.CompanyID = de.CompanyID;
                savingLang.MinimumBalance = de.MinimumBalance.Replace(".", "").Replace(".", "").Replace(".", "");
                savingLang.MaximumBalance = de.MaximumBalance.Replace(".", "").Replace(".", "").Replace(".", "");
                savingLang.Description = WebUtility.HtmlEncode(de.DescriptionLang);
                savingLang.Benefit = WebUtility.HtmlEncode(de.BenefitLang);
                savingLang.FeeContent = WebUtility.HtmlEncode(de.FeeContentLang);
                savingLang.MoreInfo = WebUtility.HtmlEncode(de.MoreInfoLang);
                savingLang.HomeLoanPlanID = de.HomeLoanPlanID;
                savingLang.Display = false;

                bll.InsertHomeLoanLang(saving, 1);
                bll.InsertHomeLoanLang(savingLang, 2);

                return RedirectToAction("ManagerHomeLoanMortgage");
            }
            return View(de);

        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteHomeLoan(int HomeLoanID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            HomeLoanTrustModels del = new HomeLoanTrustModels();

            del = bll.getHomeLoanByIDManager(HomeLoanID, lang.LangID);
            if (del != null)
            {
                bll.DeleteHomeLoan(del.HomeLoanID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }


        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult Articles()
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductBLL cardbll = new ProductBLL();
            int HomeLoanMortgageID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["HomeLoanMortgageID"].ToString());
            ProductModels card = new ProductModels();
            cardbll.getProductByID(HomeLoanMortgageID, lang.LangID);
            Models.Product c = new Models.Product();
            c.Description = WebUtility.HtmlDecode(card.Description);
            return View(c);
        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult Articles(FO.Models.Product card)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductBLL cardbll = new ProductBLL();
            int HomeLoanMortgageID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["HomeLoanMortgageID"].ToString());
            ProductModels ca = new ProductModels();
            ca = cardbll.getProductByID(HomeLoanMortgageID, lang.LangID);
            if (ca != null)
            {
                ca.Description = WebUtility.HtmlEncode(card.Description);
                cardbll.UpdateProductDesriptionLang(ca, lang.LangID);
                return RedirectToAction("ManagerHomeLoanMortgage");
            }
            return View();
        }

        [Authorize(Roles = "8,9")]
        public ActionResult FAQShowCase()
        {
            return View();
        }
        [Authorize(Roles = "8,9")]
        public ActionResult ManagerFAQ()
        {
            return View();
        }
        public JsonResult getFAQJson()
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            int HomeLoanMortgageID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["HomeLoanMortgageID"].ToString());
            ProductFAQBLL cardbll = new ProductFAQBLL();
            List<ProductFAQModels> list = new List<ProductFAQModels>();
            list = cardbll.getfaqbyproid(HomeLoanMortgageID, lang.LangID);
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertFAQ()
        {

            return View();

        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult InsertFAQ(FO.Models.ProductFAQInsert card)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductFAQBLL cardbll = new ProductFAQBLL();
            int HomeLoanMortgageID = int.Parse(System.Configuration.ConfigurationManager.AppSettings["HomeLoanMortgageID"].ToString());
            if (ModelState.IsValid)
            {
                ProductFAQModels items = new ProductFAQModels();
                items.FAQTitles = card.FAQTitles;
                items.FAQAnwers = card.FAQAnwers;
                items.ProductID = HomeLoanMortgageID;
                cardbll.InsertFAQ(items);
                ProductFAQModels faqitems = cardbll.gettop1faq();
                ProductFAQModels itemsLang = new ProductFAQModels();
                items.ProductFAQID = faqitems.ProductFAQID;
                itemsLang.ProductFAQID = faqitems.ProductFAQID;
                cardbll.InsertFAQLang(items, 1);

                itemsLang.FAQTitles = card.FAQTitlesLang;
                itemsLang.FAQAnwers = card.FAQAnwersLang;
                cardbll.InsertFAQLang(itemsLang, 2);
                return RedirectToAction("ManagerFAQ");
            }
            return View(card);

        }

        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateFAQ(int ProductFAQID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductFAQBLL cardbll = new ProductFAQBLL();
            ProductFAQModels card = new ProductFAQModels();
            card = cardbll.getfaqbyid(ProductFAQID, lang.LangID);
            Models.ProductFAQ c = new Models.ProductFAQ();
            c.FAQTitles = card.FAQTitles;
            c.FAQAnwers = card.FAQAnwers;
            return View(c);
        }
        [ValidateInput(false)]
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public ActionResult UpdateFAQ(FO.Models.ProductFAQ card)
        {
            ProductFAQBLL cardbll = new ProductFAQBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductFAQModels ca = new ProductFAQModels();
            ca = cardbll.getfaqbyid(card.ProductFAQID, lang.LangID);
            if (ca != null)
            {
                ca.FAQTitles = card.FAQTitles;
                ca.FAQAnwers = card.FAQAnwers;
                cardbll.UpdateFAQ(ca, lang.LangID);
                return RedirectToAction("ManagerFAQ");
            }

            return View();
        }

        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteFAQ(int ProductFAQID)
        {
            ProductFAQBLL bll = new ProductFAQBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            ProductFAQModels card = new ProductFAQModels();
            card = bll.getfaqbyid(ProductFAQID, lang.LangID);
            if (card != null)
            {
                bll.DeleteFAQ(card.ProductFAQID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        public ActionResult ThanksYou()
        {
            return View();
        }
        [HttpGet]
        [Authorize(Roles = "8,9")]
        public ActionResult ContractDetail(int HomeLoanApplyID)
        {
            HomeLoanTrustBLL HomeLoanTrustBLL = new HomeLoanTrustBLL();
            HomeLoanApplyModels HomeLoanapp = new HomeLoanApplyModels();
            HomeLoanapp = HomeLoanTrustBLL.getcontractbyid(HomeLoanApplyID);
            StatusBLL status = new StatusBLL();
            List<StatusModels> liststatus = new List<StatusModels>();
            liststatus = status.getStatus();
            FO.Models.HomeLoanApply c = new FO.Models.HomeLoanApply();
            ViewBag.StatusListID = new SelectList(liststatus, "StatusID", "StatusName", HomeLoanapp.StatusID);
            c.StatusID = HomeLoanapp.StatusID;
            c.CustomerName = HomeLoanapp.CustomerName;
            c.CustomerEmail = HomeLoanapp.CustomerEmail;
            c.CustomerDOB = HomeLoanapp.CustomerDOB;
            c.CustomerPhone = HomeLoanapp.CustomerPhone;
            c.CustomerIncome = HomeLoanapp.CustomerIncome;
            c.CompanyName = HomeLoanapp.CompanyName;
            c.StatusName = HomeLoanapp.StatusName;
            c.HomeLoanName = HomeLoanapp.HomeLoanName;
            c.HomeLoanID = HomeLoanapp.HomeLoanID;
            c.CompanyImg = HomeLoanapp.CompanyImg;
            c.CompanyName = HomeLoanapp.CompanyName;
            c.AppDate = HomeLoanapp.AppDate;
            return View(c);
        }
        [HttpPost]
        [ValidateInput(false)]
        [Authorize(Roles = "8,9")]
        public ActionResult ContractDetail(FO.Models.HomeLoanApply HomeLoan)
        {
            HomeLoanTrustBLL HomeLoanTrustBLL = new HomeLoanTrustBLL();
            HomeLoanApplyModels HomeLoanapp = new HomeLoanApplyModels();
            HomeLoanapp = HomeLoanTrustBLL.getcontractbyid(HomeLoan.HomeLoanApplyID);
            StatusBLL status = new StatusBLL();
            List<StatusModels> liststatus = new List<StatusModels>();
            liststatus = status.getStatus();
            ViewBag.StatusListID = new SelectList(liststatus, "StatusID", "StatusName", HomeLoanapp.StatusID);
            if (HomeLoanapp != null)
            {
                HomeLoanapp.StatusID = HomeLoan.StatusID;
                HomeLoanTrustBLL.UpdateStatus(HomeLoanapp);
                return RedirectToAction("Contract");
            }
            return View();
        }
        [Authorize(Roles = "8,9")]
        public ActionResult Contract()
        {
            StatusBLL status = new StatusBLL();
            List<StatusModels> liststatus = new List<StatusModels>();
            liststatus = status.getStatus();
            ViewBag.StatusID = liststatus;
            return View();
        }
        public JsonResult getContract()
        {

            HomeLoanTrustBLL HomeLoanTrustBLL = new HomeLoanTrustBLL();
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            List<HomeLoanApplyModels> list = new List<HomeLoanApplyModels>();
            list = HomeLoanTrustBLL.getcontractbycateid(2);
            return Json(list, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        [Authorize(Roles = "8,9")]
        public JsonResult DeleteHomeLoanApply(int HomeLoanApplyID)
        {
            LanguageBLL langbll = new LanguageBLL();
            Language lang = langbll.getLangByCode(Request.Cookies["_culture"]["lang"]);
            HomeLoanTrustBLL bll = new HomeLoanTrustBLL();
            HomeLoanApplyModels HomeLoan = new HomeLoanApplyModels();
            HomeLoan = bll.getcontractbyid(HomeLoanApplyID);
            if (HomeLoan != null)
            {
                bll.DeleteHomeLoanApply(HomeLoan.HomeLoanApplyID);
                var result = new { Status = "OK" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { Status = "Xóa thất bại" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }

        }
        [HttpPost]
        public ActionResult SendEmail(string Name, string phone, string emailuser, int CardID)
        {
            try
            {
                string MailFromUserName = ConfigurationManager.AppSettings["MailFromUserName"].ToString();
                string MailFromPassword = ConfigurationManager.AppSettings["MailFromPassword"].ToString();
                string MailSMTP = ConfigurationManager.AppSettings["MailSMTP"].ToString();
                string MailCC = ConfigurationManager.AppSettings["MailCC"].ToString();
                string MailSendTo = ConfigurationManager.AppSettings["MailSendTo"].ToString();
                Models.EmailSend email = new Models.EmailSend();
                email.EmailSendTo = MailSendTo;
                email.Subject = "Khách hàng " + Name + " Apply Vay mua nhà có thế chấp tài sản đảm bảo ID: " + CardID + "";
                email.Body = "";
                email.Body += "<p>Hi, Admin</p>";
                email.Body += "<p>Khách hàng: " + Name + " Apply Vay mua nhà có thế chấp tài sản đảm bảo ID: " + CardID + "</p>";
                email.Body += "<p>Email: " + emailuser + "</p>";
                email.Body += "<p>SĐT: " + phone + "</p>";
                email.Body += "<p><a href='http://www.vnbanknet.com/HomeLoanMortgage/ContractDetail/" + CardID + "'>Link chi tiết</a></p>";
                email.Body += "<p>Thanks</p>";
                MailMessage message = new MailMessage();
                message.Body = email.Body;
                message.IsBodyHtml = true;
                message.From = new System.Net.Mail.MailAddress(MailFromUserName);
                message.To.Add(email.EmailSendTo);
                message.CC.Add(MailCC);
                message.Subject = email.Subject;

                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(MailSMTP);// you need an smtp server address to send emails
                smtp.Credentials = new System.Net.NetworkCredential(MailFromUserName, MailFromPassword); //missing line from ur code
                smtp.Port = 587;  //missing line from your code
                smtp.EnableSsl = true;   //missing line from your code
                smtp.Send(message);
                int result = 1;
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            catch
            {
                int result = -1;
                return Json(result, JsonRequestBehavior.AllowGet);
            }
        }
    }
}
